<?php
namespace app\common\controller;

use think\Controller;
use think\Request;

class Image extends Controller{

    //上传文件
    public function upload(){
        $file = Request::instance()->file('file');
        if ($file){
            $path = ROOT_PATH . 'public' . DS . 'upload' . DS . 'image';
            $info = $file->move($path);
            if ($info && $info->getPathname()) {
                $sub_dir = get_random_sn();//获取随机的id
                // 成功上传后 获取上传信息
                $image = config('setting.image_prefix') . $info->getSaveName();
                //return show(1, 'success', [ 'id'=>$sub_dir, 'name'=>$info->getFilename(), 'path'=>$image]);
                return show(1, 'success', [ 'filePath'=>$image]);
            }
        }
        return show(0, 'upload error');
    }

}
